package com.example.JcGQS.controller;

import com.example.JcGQS.pojo.dto.DeleteCategoryDTO;
import com.example.JcGQS.pojo.dto.InsertCategoryDTO;
import com.example.JcGQS.pojo.dto.PageDTO;
import com.example.JcGQS.pojo.dto.UpdateCategoryDTO;
import com.example.JcGQS.pojo.entity.GoodsCategory;
import com.example.JcGQS.pojo.vo.DataRecordVo;
import com.example.JcGQS.response.ResultUtil;
import com.example.JcGQS.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 物品类型控制器
 *
 * @author 末日
 * @date 2023年11月10日
 */
@RestController
@RequestMapping("/GQS/category")
public class CategoryController {
    @Autowired
    CategoryService categoryService;

    /**
     * 新增物品类型
     * @return
     */
    @PostMapping("/insert")
    public void insertCategory(@RequestBody InsertCategoryDTO insertCategoryDTO, HttpServletRequest request){
        String token = request.getHeader("Authorization");
         categoryService.insertCategory(insertCategoryDTO,token);
    }

    /**
     * 删除物品类型
     * @return
     */
    @PostMapping("/delete")
    public void deleteCategory(@RequestBody DeleteCategoryDTO deleteCategoryDTO, HttpServletRequest request){
        String token = request.getHeader("Authorization");
         categoryService.deleteCategory(deleteCategoryDTO,token);
    }

    /**
     * 修改物品类型
     * @return
     */
    @PostMapping("/update")
    public void updateCategory(@RequestBody UpdateCategoryDTO updateCategoryDTO, HttpServletRequest request){
        String token = request.getHeader("Authorization");
         categoryService.updateCategory(updateCategoryDTO,token);
    }

    /**
     * 获取物品类型列表
     * @return
     */
    @PostMapping("/list")
    public DataRecordVo<GoodsCategory> categoryList(@RequestBody PageDTO pageDTO, HttpServletRequest request){
        String token = request.getHeader("Authorization");
        return categoryService.categoryList(pageDTO,token);
    }


}
